# aggregate polygons to zip2 for plotting 

### Inputs: 
# "OrigData/tl_2017_us_zcta510/tl_2017_us_zcta510.shp")

# Outputs: 
# "OrigData/zip3geo"
# "OrigData/zip2geo"

### edit working directory here: 
setwd("/Users/uqalanau/Dropbox/AirPollutionCognition/Stata") 

library(rgdal)
library(maptools)
library(tidyverse)
library(sf)
library(dplyr)

zip5 = read_sf("OrigData/tl_2017_us_zcta510/tl_2017_us_zcta510.shp")

zip3 <- 
  zip5 %>%
  mutate(zip3 = floor(as.numeric(zip5$ZCTA5CE10)/100)) %>%
  group_by(zip3) %>%
  summarise()
  
save(zip3,file="OrigData/zip3geo")



zip2 <- 
  zip3 %>%
  mutate(zip2 = floor(zip3/10)) %>%
  group_by(zip2) %>%
  summarise()


save(zip2,file="OrigData/zip2geo")

